/*
 * @lc app=leetcode.cn id=989 lang=javascript
 *
 * [989] 数组形式的整数加法
 */

// @lc code=start
/**
 * @param {number[]} num
 * @param {number} k
 * @return {number[]}
 */
var addToArrayForm = function (num, k) {
    let resArry = [];
    let carry = 0;
    let l = num.length - 1
    while (l >= 0 || k > 0) {
        const x = l < 0 ? 0 : num[l];
        const y = k % 10

        let res = x + y + carry;
        carry = Math.floor(res / 10)
        resArry.unshift(res % 10);

        l--;
        k = Math.floor(k / 10)
    }
    if (carry) resArry.unshift(carry)
    return resArry
};
// @lc code=end

